﻿///<reference path="../../../portal.js"/>
var SimplePager = function() {

	//public area
	return {
		Init: function(pager, pageCallback) {
			var rpList = $("#rpList").val(pager.RowPerPage);
			var cPage = $("#tbxCPage");
			var txtTip = $("#txtTip");
			//当前页
			cPage.change(function() {
				if (isInt(this.value)) {
					this.value = pager.CurrentPage;
				} else {
					var _val = parseInt(this.value);
					if (_val >= 1 && _val <= pager.PageTotal) {
						//do nothing
					} else {
						this.value = pager.CurrentPage;
					}
				}
			});
			cPage.keydown(function(event) {
				if (isEnter(event)) {
					return false;
				}
			});
			//每页行数变化时
			rpList.change(function() {
				pageCallback.apply(pageCallback, [{CurrentPage:1,RowPerPage:rpList.val()}]);
			});
			//刷新时
			$("#btnReload").click(function(event) {
				pageCallback.apply(pageCallback, [{ CurrentPage: cPage.val(), RowPerPage: rpList.val()}]);
				event.preventDefault();
			});
			//点击最前页
			$("#btnFst").click(function(event) {
				cPage.val(1);
				pageCallback.apply(pageCallback, [{ CurrentPage: 1, RowPerPage: rpList.val()}]);
				event.preventDefault();
			});
			//点击前一页
			$("#btnPrev").click(function(event) {
				if (pager.CurrentPage == 1) return false;
				cPage.val(pager.CurrentPage - 1);
				pageCallback.apply(pageCallback, [{ CurrentPage: pager.CurrentPage - 1, RowPerPage: rpList.val()}]);
				event.preventDefault();
			});
			//点击下一页
			$("#btnNext").click(function(event) {
				if (pager.CurrentPage == pager.PageTotal) return false;
				cPage.value = pager.CurrentPage + 1;
				pageCallback.apply(pageCallback, [{ CurrentPage: pager.CurrentPage + 1, RowPerPage: rpList.val()}]);
				event.preventDefault();
			});
			//点击最后页
			$("#btnLst").click(function(event) {
				cPage.value = pager.PageTotal;
				pageCallback.apply(pageCallback, [{ CurrentPage: pager.PageTotal, RowPerPage: rpList.val()}]);
				event.preventDefault();
			});
		} //endof Init
	};
} ();